package com.atguigu.yygh.hosp.controller.api;

import com.atguigu.yygh.hosp.bean.Result;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.utils.HttpRequestHelper;
import com.atguigu.yygh.model.hosp.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/*==========================================
      时 间:   2022-04-19
      讲 师:   刘  辉
      描 述:   尚硅谷教学团队
 ==========================================*/
@RestController
@RequestMapping("/api/hosp")
public class ApiDepartmentController {

    @Autowired
    private DepartmentService departmentService;

    //
    @PostMapping("/department/remove")
    public Result remove(HttpServletRequest request){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(request.getParameterMap());
        //todo:校验
        departmentService.remove(stringObjectMap);
        return Result.ok();
    }


    //department/list
    @PostMapping("/department/list")
    public Result getDepartmentList(HttpServletRequest request){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(request.getParameterMap());
        //todo:校验
        Page<Department> departmentPage=departmentService.getDepartmentPage(stringObjectMap);
        return Result.ok(departmentPage);
    }



    @PostMapping("/saveDepartment")
    public Result save(HttpServletRequest request){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(request.getParameterMap());
        //todo:sign校验
        departmentService.save(stringObjectMap);
        return Result.ok();
    }
}
